home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
tex
/
td187src.lzh
/
MAGICSTR.I
< prev
next >
Wrap
Text File
|
1991-06-21
|
8KB
|
301 lines
(*#######################################################################
M A G I C S T R I N G S
#######################################################################
V1.1 09.06.91 Jens Pirnay Routinen durch MM2-Bib ersetzt.
V1.0 18.10.90 Johannes Leckebusch/Peter Hellinger MM2-Modula-2
#######################################################################*)
IMPLEMENTATION MODULE MagicStrings;
(*------------------------------*)
(* MM2-Version: AKTIVIERT *)
(*------------------------------*)
(*$R- Range-Checks *)
(*$S- Stack-Check *)
(* *)
(*------------------------------*)
FROM MagicSys IMPORT Nil, Null, Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6,
Bit7, Bit8, Bit9, Bit10, Bit11, Bit12, Bit13, Bit14,
Bit15, LOC, Byte, ByteSet, sWORD, sINTEGER, sCARDINAL,
sBITSET, lWORD, lINTEGER, lCARDINAL, lBITSET,
CastToChar, CastToByte, CastToByteset, CastToInt,
CastToCard, CastToBitset, CastToWord, CastToLInt,
CastToLCard, CastToLBitset, CastToLWord, CastToAddr;
IMPORT Strings;
(** Alles durch Aufrufe der MM2-Bibliothek ersetzt, da hier eine Menge
Bugs lauern (genaueres steht in der TDI-Version)... JP
(* BEMERKUNG: In diesem Modul werden fuer die Index-Zaehler INTEGER-
* Variable benutzt, weil es sonst bei Ausdruecken der Form
* "Laenge - 1" zu Bereichsfehler kommt, wenn Laenge = 0 und
* Laenge = TYPE CARDINAL.
*)
CONST Ch0 = 0C;
PROCEDURE Length (VAR str: ARRAY OF CHAR): sCARDINAL;
VAR i: sCARDINAL;
BEGIN
FOR i:= 0 TO HIGH (str) DO
IF (str[i] = Ch0) THEN RETURN i; END;
END;
RETURN HIGH (str);
END Length;
PROCEDURE Equal (s1, s2: ARRAY OF CHAR): BOOLEAN;
VAR i, l1, l2: sINTEGER;
BEGIN
l1:= Length (s1);
l2:= Length (s2);
IF l1 # l2 THEN RETURN FALSE END;
FOR i:= 0 TO l1 DO
IF s1[i] # s2[i] THEN RETURN FALSE; END;
END; (* FOR *)
RETURN TRUE;
END Equal;
(*$Z-*)
PROCEDURE fastCompare (VAR s1, s2: ARRAY OF CHAR): Relation;
(*$Z=*)
(*$L-*)
BEGIN
(*
IF s1[0] > s2[0] THEN
RETURN greater
ELSIF s1[0] < s2[0] THEN
RETURN less
ELSE
RETURN Compare (s1,s2)
END
*)
ASSEMBLER
MOVE.L -12(A3),A1 ; ADR (s1)
MOVE.L -06(A3),A2 ; ADR (s2)
MOVE.B (A1),D1 ; s1[0]
MOVE.B (A2),D2 ; s2[0]
CMP.B D2,D1
BHI gr
BCS le
JMP Compare ; s1[0] = s2[0]
le: SUBA.W #12,A3
MOVE #less,(A3)+
RTS
gr: SUBA.W #12,A3
MOVE #greater,(A3)+
END
END fastCompare;
(*$L=*)
PROCEDURE Compare (s1, s2: ARRAY OF CHAR): Relation;
VAR l, i, l1, l2: sINTEGER;
equ: Relation;
BEGIN
(**
equ:= equal;
l1:= Length (s1);
l2:= Length (s2);
IF l1 > l2 THEN l:= l2; ELSE l:= l1; END;
i:= 0;
WHILE (i < l) AND (equ = equal) DO
IF s1[i] > s2[i] THEN equ:= greater
ELSIF s1[i] < s2[i] THEN equ:= less;
END;
INC (i);
END;
IF equ = equal THEN
IF l1 > l2 THEN equ:= greater
ELSIF l1 < l2 THEN equ:= less
END;
END;
RETURN equ;
**)
RETURN fastCompare(s1, s2);
END Compare;
PROCEDURE Assign (quelle: ARRAY OF CHAR; VAR ziel: ARRAY OF CHAR);
VAR i, l, hq, hz: sCARDINAL;
BEGIN
FOR i:= 0 TO HIGH (ziel) DO
IF (quelle[i] = Ch0) OR (i > HIGH(quelle)) THEN
ziel[i]:= Ch0;
RETURN;
END;
ziel[i]:= quelle[i];
END;
END Assign;
PROCEDURE Pos (substr, str: ARRAY OF CHAR): sCARDINAL;
VAR index, i, laenge, h: sINTEGER;
gefunden: BOOLEAN;
test: BOOLEAN;
BEGIN
index:= 0; gefunden:= FALSE; laenge:= Length (substr); h:= HIGH (str);
WHILE NOT gefunden AND ((index + laenge) <= h) DO
test:= TRUE; i:= 0;
WHILE (i < laenge) AND test DO
test:= substr [i] = str [index + i]; INC (i);
END;
gefunden:= test;
INC (index);
END (* WHILE NOT gefunden *);
IF (gefunden) AND (index > 0) THEN RETURN index - 1;
ELSE RETURN h + 1;
END;
END Pos;
PROCEDURE Insert (substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR; inx: sCARDINAL);
VAR i, in, h, l, l1: sINTEGER;
BEGIN
l1:= Length (substr); h:= HIGH (str); in:= inx;
IF l1 = 0 THEN RETURN END;
l:= Length (str); l:= l + l1 - 1;
FOR i:= l TO (in + l1) BY -1 DO str[i]:= str[i - l1]; END;
IF (l + 1) <= h THEN str [l + 1]:= Ch0; END;
FOR i:= 0 TO l1 - 1 DO str[i + in]:= substr[i]; END;
END Insert;
PROCEDURE Delete (VAR str: ARRAY OF CHAR; inx, len: sCARDINAL);
VAR i, l, h, in, le: sINTEGER;
BEGIN
l:= Length (str); in:= inx; le:= len; h:= HIGH (str);
FOR i:= in TO (l - le) - 1 DO str[i]:= str[i + le]; END;
IF (l - le) <= h THEN str[l - le]:= Ch0;
END;
END Delete;
PROCEDURE Append (substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR);
VAR i, j, l: sCARDINAL;
BEGIN
l:= Length (str); j:= 0;
FOR i:= l TO HIGH(str) DO
IF (substr[j] = Ch0) OR (j > HIGH(substr)) THEN
str[i]:= Ch0;
RETURN;
END;
str[i]:= substr[j]; INC (j);
END;
END Append;
PROCEDURE Copy (VAR str: ARRAY OF CHAR; inx, len: sCARDINAL;
VAR result: ARRAY OF CHAR);
VAR i, in, le, h: sINTEGER;
BEGIN
in:= inx; le:= len; h:= HIGH (result);
FOR i:= 0 TO le - 1 DO result[i]:= str[in + i]; END;
IF le <= h THEN result [le]:= Ch0; END;
END Copy;
PROCEDURE CAPS (VAR str: ARRAY OF CHAR);
VAR i, l: INTEGER;
BEGIN
l:= Length (str);
FOR i:= 0 TO l - 1 DO str[i]:= Cap (str[i]); END;
END CAPS;
PROCEDURE Cap (ch: CHAR): CHAR;
BEGIN
CASE ch OF
'ä': RETURN 'Ä';|
'ö': RETURN 'Ö';|
'ü': RETURN 'Ü';|
'é': RETURN 'É';|
'à': RETURN 'À';|
'å': RETURN 'Å';|
'ç': RETURN 'Ç';|
'æ': RETURN 'Æ';|
'ñ': RETURN 'Ñ';|
'ã': RETURN 'Ã';|
'õ': RETURN 'Õ';|
'ø': RETURN 'Ø';|
'œ': RETURN 'Œ';|
ELSE RETURN CAP(ch);
END;
END Cap;
**)
PROCEDURE Length (REF str: ARRAY OF CHAR): sCARDINAL;
BEGIN
RETURN LENGTH(str); (* neue ISO-Standard-Funktion *)
END Length;
PROCEDURE Pos (substr, str: ARRAY OF CHAR): sCARDINAL;
VAR i : sINTEGER;
BEGIN
i := Strings.Pos(substr, str, 0);
IF i<0 THEN
RETURN HIGH(str) + 1;
ELSE
RETURN CastToCard(i);
END;
END Pos;
PROCEDURE Insert (substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR; index: sCARDINAL);
VAR success : BOOLEAN;
BEGIN
Strings.Insert(substr, CastToInt(index), str, success);
END Insert;
PROCEDURE Delete (VAR str: ARRAY OF CHAR; index, len: sCARDINAL);
VAR success : BOOLEAN;
BEGIN
Strings.Delete(str, index, len, success);
END Delete;
PROCEDURE Append (substr: ARRAY OF CHAR; VAR str: ARRAY OF CHAR);
VAR success : BOOLEAN;
BEGIN
Strings.Append(substr, str, success);
END Append;
PROCEDURE Copy (REF str: ARRAY OF CHAR; index, len: sCARDINAL;
VAR result: ARRAY OF CHAR);
VAR success : BOOLEAN;
BEGIN
Strings.Copy(str, CastToInt(index), CastToInt(len), result, success);
END Copy;
PROCEDURE CAPS (VAR str: ARRAY OF CHAR);
BEGIN
Strings.Upper(str);
END CAPS;
PROCEDURE Equal (s1, s2: ARRAY OF CHAR): BOOLEAN;
BEGIN
RETURN Strings.StrEqual(s1, s2);
END Equal;
PROCEDURE Compare (s1, s2: ARRAY OF CHAR): Relation;
VAR res : Strings.Relation;
BEGIN
res := Strings.Compare(s1, s2);
RETURN Relation(res);
END Compare;
PROCEDURE Assign (quelle: ARRAY OF CHAR; VAR ziel: ARRAY OF CHAR);
VAR success : BOOLEAN;
BEGIN
Strings.Assign(quelle, ziel, success);
END Assign;
PROCEDURE Cap (ch: CHAR): CHAR;
(* Wandelt auch deutsche Umlaute *)
BEGIN
RETURN CAP(ch); (* macht das Standard-MM2 schon *)
END Cap;
END MagicStrings.